import Vue from "vue"

const CONSOLE_ERROR = console.error

const HandleError = (...args) => {
	return CONSOLE_ERROR.apply(console, args)
}

/**
 * 捕获console异常
 */
console.error = function (...args) {
	HandleError(...args)
}

/**
 * 捕获Vue异常
 */
Vue.config.errorHandler = (error, vm, info) => {
	HandleError(error)
}

/**
 * 捕获Window异常
 */
window.addEventListener("error", event => {
	HandleError(event.error)
})

/**
 * 捕获Promise异常
 */
window.addEventListener("unhandledrejection", error => {
	HandleError(error.reason)
})
